// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import router from './router'
import ElementUI from 'element-ui'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import axios from './http'
import NProgress from 'nprogress' /*进度条*/
import 'nprogress/nprogress.css'
import './assets/iconfont/iconfont.css'
Vue.use(ElementUI, { size: 'small', zIndex: 3000 });
Vue.config.productionTip = false;

NProgress.configure({ease:'ease',speed:500});

/**/
Vue.prototype.$axios = axios;
/*设置全局的cookie*/
Vue.prototype.setCookie = function (cname,cvalue,exdays) {
  let d = new Date();
  d.setTime(d.getTime()+(exdays*24*60*60*1000));
  let expires ='expires='+d.toGMTString();
  document.cookie = cname + '=' + cvalue +';'+expires
};
Vue.prototype.getCookie = function (cname) {
  let name = cname +"=";
  let ca = document.cookie.split(';');
  for(var i=0; i<ca.length; i++)
  {
    var c = ca[i].trim();
    if (c.indexOf(name)==0) return c.substring(name.length,c.length);
  }
  return "";
};

/*对路由权限进行跳转*/
router.beforeEach((to,from,next)=>{
  NProgress.start();
  const isLogin = localStorage.mytoken ? true : false;
  if(to.path=='/'){
    next()
  }else {
    isLogin ? next():next('/')
  }
});
router.afterEach(transition =>{
  NProgress.done();
});

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
});
